package com.ydd.common.util;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;


/**
 * 创建指定数量的随机字符串的帮助类，提供静态方法，不可以实例化。
 */
public class CraterSmsCode {
	/**
	 * 禁止实例化
	 */
	private CraterSmsCode() {
	}
	
	/**
	 * 数字
	 */
	public static final String NUMONlY = "1234567890";
	/**
	 * 小写字母和数字
	 */
	public static final String NUMLETTER ="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	/** 
	  * 创建指定数量的随机字符串 
	  * @param numberFlag 是否是数字 
	  * @param length 长度
	  * @return 
	  */  
	 public static String createRandom(boolean numberFlag, int length){  
	  String retStr = "";  
	  String strTable = numberFlag ? NUMONlY :NUMLETTER ;  
	  int len = strTable.length();  
	  boolean bDone = true;  
	  do {  
	   retStr = "";  
	   int count = 0;  
	   for (int i = 0; i < length; i++) {  
	    double dblR = Math.random() * len;
	    if (i == 0) {
	    	dblR = Math.random() * (len - 1);
		}
	    int intR = (int) Math.floor(dblR);  
	    char c = strTable.charAt(intR);  
	    if (('0' <= c) && (c <= '9')) {  
	     count++;  
	    }  
	    retStr += strTable.charAt(intR);  
	   }  
	   if (count >= 2) {  
	    bDone = false;  
	   }  
	  } while (bDone);  
	  
	  return retStr;  
	 } 

	 public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
			String result = createRandom(true,6);
			System.out.println(result);
			String smsresult = "000/0002/00025";
			String[] sms = smsresult.split("/");
			System.out.println(sms[0]);
			
			
			System.out.println(StrUtils.isEmpty(""));
		}
	 
}
